<?php
class ProtocolAction extends BaseAction {
	public  function show() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$News = M('News');
		$condition['type'] = '0';
		
		$id=$_GET['id'];
		if($id==1) {
			$condition['sort'] = '公司简介';
			$navi="公司简介";
			$title="简介内容";
		}
		else if($id==2) {
			$condition['sort'] = '注册协议';
			$navi="注册协议";
			$title="协议内容";
		}
		else if($id==3) {
			$condition['sort'] = '联系我们';
			$navi="联系我们";
			$title="联系内容";
		}
		else if($id==4) {
			$condition['sort'] = '免责申明';
			$navi="免责申明";
			$title="申明内容";
		}
		else if($id==5) {
			$condition['sort'] = '服务条款';
			$navi="服务条款";
			$title="条款内容";
		}
		
		$info = $News->where($condition)->find();
		$this->assign('navi',$navi);
		$this->assign('title',$title);
		$this->assign('page',$info);
		$this->display();
	}
	
	public function modify() {
		// 防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$News = M('News');
		$condition['type'] = '0';
		$condition['sort'] = $_POST['type'];
		if($_POST['type']=='公司简介') $jumpurl='1';
		else if($_POST['type']=='注册协议') $jumpurl='2';
		else if($_POST['type']=='联系我们') $jumpurl='3';
		else if($_POST['type']=='免责申明') $jumpurl='4';
		else if($_POST['type']=='服务条款') $jumpurl='5';
		$info = $News->where($condition)->find();
		// 判断是否已经存在
		if($info) {
			if($info['createTime']!=$_POST['date']) $data['createTime'] = $_POST['date'];
			if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			if($data) {
				$result = $News->where($condition)->save($data);
				if($result)
					echo "<script language=\"javascript\">alert('更新成功！');window.location.href='show/id/".$jumpurl."';</script>";
				else 
					$this->error ( '数据写入错误！请重试...' );
			}
			else echo "<script language=\"javascript\">alert('资料没有更新！');window.history.back();</script>";
		} else {
			$data['type'] = '0';
			$data['sort'] = $_POST['type']; 
			$data['createTime'] = $_POST['date'];
			$data['author'] = $_SESSION['admin']['admName'];
			$data['title'] = $_POST['title'];
			$data['content'] = $_POST['content'];
			$data['modifyTime'] = date('Y-m-d H:i:s',time());
			$result = $News->add($data);
			if($result)
				echo "<script language=\"javascript\">alert('更新成功！');window.location.href='show/id/".$jumpurl."';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
	}
}